﻿using System;
using System.Configuration;

namespace CrazyTalk.Common
{
    /// <summary>
    /// web.config操作类
    /// Copyright (C) Maticsoft
    /// </summary>
    public sealed class ConfigHelper
    {
        /// <summary>
        /// 得到AppSettings中的配置字符串信息
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetConfigString(string key)
        {
            string CacheKey = "AppSettings-" + key;
            object objModel = DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = ConfigurationManager.AppSettings[key];
                    if (objModel != null)
                    {
                        DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(180), TimeSpan.Zero);
                    }
                }
                catch
                { }
            }
            return objModel.ToString();
        }

        /// <summary>
        /// 得到AppSettings中的配置Bool信息
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static bool GetConfigBool(string key)
        {
            bool result = false;
            string cfgVal = GetConfigString(key);
            if (null != cfgVal && string.Empty != cfgVal)
            {
                try
                {
                    result = bool.Parse(cfgVal);
                }
                catch (FormatException)
                {
                    // Ignore format exceptions.
                }
            }
            return result;
        }
        /// <summary>
        /// 得到AppSettings中的配置Decimal信息
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static decimal GetConfigDecimal(string key)
        {
            decimal result = 0;
            string cfgVal = GetConfigString(key);
            if (null != cfgVal && string.Empty != cfgVal)
            {
                try
                {
                    result = decimal.Parse(cfgVal);
                }
                catch (FormatException)
                {
                    // Ignore format exceptions.
                }
            }

            return result;
        }
        /// <summary>
        /// 得到AppSettings中的配置int信息
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static int GetConfigInt(string key)
        {
            int result = 0;
            string cfgVal = GetConfigString(key);
            if (null != cfgVal && string.Empty != cfgVal)
            {
                try
                {
                    result = int.Parse(cfgVal);
                }
                catch (FormatException)
                {
                    // Ignore format exceptions.
                }
            }

            return result;
        }

        public static string UploadPath
        {
            get
            {
                try
                {
                    return System.Configuration.ConfigurationManager.AppSettings["UploadPath"];
                }
                catch
                {
                    return "/Upload";
                }
            }
        }

        /// <summary>
        /// 游戏滚动图片
        /// </summary>
        public static string GamesScrollPath
        {
            get
            {
                try
                {
                    return System.Configuration.ConfigurationManager.AppSettings["GamesUploadPathscroll"];
                }
                catch
                {
                    return "/UpLoad/Games";
                }
            }
        }


        /// <summary>
        /// 游戏大图
        /// </summary>
        public static string GamesUploadPath
        {
            get
            {
                try
                {
                    return System.Configuration.ConfigurationManager.AppSettings["GamesUploadPath"];
                }
                catch
                {
                    return "/UpLoad/Games/scroll";
                }
            }
        }

        public static string GiftsUploadPath
        {
            get
            {
                try
                {
                    return System.Configuration.ConfigurationManager.AppSettings["GiftsUploadPath"];
                }
                catch
                {
                    return "/UpLoad/Gifts";
                }
            }
        }
        public static string PayImgUploadPath
        {
            get
            {
                try
                {
                    return System.Configuration.ConfigurationManager.AppSettings["PayImgUploadPath"];
                }
                catch
                {
                    return "/UpLoad/PayImg";
                }
            }
        }
        /// <summary>
        /// 首页滚动缩略小图
        /// </summary>
        public static string GamesUploadPathum
        {
            get
            {
                try
                {
                    return System.Configuration.ConfigurationManager.AppSettings["GamesUploadPathum"];
                }
                catch
                {
                    return "/UpLoad/Games/thum";
                }
            }
        }
        /// <summary>
        /// 火爆Or推荐缩略图
        /// </summary>
        public static string GamesUploadPathHuoRecommended
        {
            get
            {
                try
                {
                    return System.Configuration.ConfigurationManager.AppSettings["GamesUploadPathHuoRecommended"];
                }
                catch
                {
                    return "/UpLoad/Games/HuoRecommended";
                }
            }
        }
        /// <summary>
        /// 普通状态缩略图
        /// </summary>
        public static string GamesUploadPathOrdinary
        {
            get
            {
                try
                {
                    return System.Configuration.ConfigurationManager.AppSettings["GamesUploadPathOrdinary"];
                }
                catch
                {
                    return "/UpLoad/Games/Ordinary";
                }
            }
        }
        /// <summary>
        /// Logol游戏图片路径
        /// </summary>
        public static string logoPath
        {
            get
            {
                try
                {
                    return ConfigurationManager.AppSettings["logoPath"];
                }
                catch
                {

                    return "/Upload/PlatTopImg/";
                }

            }
        }
        /// <summary>
        /// 网吧营业执照图片
        /// </summary>
        public static string BusinessLicensePath
        {
            get
            {
                try
                {
                    return ConfigurationManager.AppSettings["BusinessLicensePath"];
                }
                catch
                {

                    return "/Upload/BusinessLicenseImg/";
                }

            }
        }
        /// <summary>
        /// 平台域名链接
        /// </summary>
        public static string platlink
        {
            get
            {
                return ConfigurationManager.AppSettings["platlink"];
            }
        }

        /// <summary>
        /// API 授权码
        /// </summary>
        public static string ApiCode
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["apicode"];
            }
        }

        /// <summary>
        /// API key
        /// </summary>
        public static string ApiKey
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["platapikey"];
            }
        }

        /// <summary>
        /// API Url
        /// </summary>
        public static string ApiUrl
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["apiurl"];
            }
        }
        /// <summary>
        /// 签名字符串
        /// </summary>
        /// <param name="prestr">需要签名的字符串</param>
        /// <returns>签名结果</returns>
        public static string Sign(string prestr)
        {
            return MD5.MD5Encrypt(prestr);
        }
        /// <summary>
        /// 平台审核接收手机号
        /// </summary>
        public static string mobile
        {
            get { return ConfigurationManager.AppSettings["mobile"]; }
        }
        /// <summary>
        /// 短信内容
        /// </summary>
        public static string content
        {
            get { return ConfigurationManager.AppSettings["content"]; }
        }
        public static string power
        {
            get { return ConfigurationManager.AppSettings["power"]; }
        }
    }
}
